package com.wjh.yygh.controller;

import com.wjh.yygh.common.result.Result;
import com.wjh.yygh.model.hosp.Hospital;
import com.wjh.yygh.service.HospitalService;
import com.wjh.yygh.vo.hosp.HospitalQueryVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/admin/hosp/hospital")
@Api(tags = "医院接口")
public class HospitalController {

    @Autowired
    private HospitalService hospitalService;

    @ApiOperation(value = "显示所有医院")
    @GetMapping("/list/{page}/{limit}")
    public Result listHosp(@PathVariable("page") Integer page
            , @PathVariable("limit") Integer limit
            ,@RequestBody(required = false) HospitalQueryVo hospitalQueryVo) {

        Page<Hospital> pageModel = hospitalService.selectHospPage(page, limit, hospitalQueryVo);
//        List<Hospital> content = pageModel.getContent();
//        long totalElements = pageModel.getTotalElements();
        return Result.ok(pageModel);
    }

    @ApiOperation(value = "更改医院状态")
    @GetMapping("/updateStatus/{id}/{status}")
    public Result lock(@PathVariable("id") @ApiParam(name = "id" ,value = "医院id",required = true) String id ,
            @PathVariable("status") @ApiParam(name = "status" ,value = "状态： 0未上线 1 已上线",required = true) Integer status){
        hospitalService.updateStatus(id ,status);
        return Result.ok().message("更新成功");

    }

    @ApiOperation(value = "医院详情页")
    @GetMapping(value = "/showHospDetail/{id}")
    public Result showHospDetail(@PathVariable("id") String id){
        Map<String, Object> hospById = hospitalService.getHospById(id);
        return Result.ok(hospById);
    }




}
